import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

    private MyDatabaseHelper dbHelper;
    private TextView tvScore;
    private TextView MAXScore;
    private ImageView againGame;
    private int score = 0;
    private SQLiteDatabase db;

    //提供一个单例设计模式给别的类去调用该类中的处理分数的方法
    private static MainActivity mainActivity = null;
    public MainActivity(){
        mainActivity = this;
    }
    public static MainActivity getMainActivity(){
        return mainActivity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏状态栏和标题栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_main);

        tvScore = (TextView) findViewById(R.id.tvScore);
        MAXScore = (TextView) findViewById(R.id.Maxscore);

        //建立数据库
        dbHelper = new MyDatabaseHelper(this,"MAXScore.db",null,1);
        dbHelper.getWritableDatabase();

    }

    //分数清零
    public void clearScore(){
        score = 0;
        showscore();
    }
    //使用方法添加分数，并显示出来
    public void addScore(int s){
        score += s;
        showscore();
    }

    public void saveScore(){
        String s = tvScore.getText().toString();
        db=dbHelper.getWritableDatabase();
        String maxScore = dbHelper.query(db);
        dbHelper.Update(db,s,maxScore);
    }
    //在控件上显示分数
    public void showscore(){
        tvScore.setText(score+"");
    }

    //显示最高分
    public void showMaxscore(){
        db=dbHelper.getWritableDatabase();
        String maxScore = dbHelper.query(db);
        MAXScore.setText(maxScore+"");
    }

}